﻿// MIT License
// 开源地址：https://gitee.com/co1024/AbcMvc
// Copyright (c) 2021-2023 1024
// Abc.Mvc=Furion+EF+SqlSugar+Pear layui admin.

using System.Data;

namespace Abc.Utils;

public static class ExcelHelper
{
    /*
      XLS  转 XLSX 参考：https://www.cnblogs.com/HelloQLQ/p/16166140.html
     */

    /// <summary>
    /// XLS  转 XLSX
    /// </summary>
    /// <param name="xlsPath">xls 文件路径</param>
    /// <returns></returns>
    public static string XlsToXlsx(string xlsPath)
    {
        return xlsPath.XlsToXlsx();
    }

    ///<summary>
    /// 将excel导入到 List<IDictionary<string, object>
    /// </summary>
    /// <param name="filePath">excel路径</param>
    /// <param name="headRowIndex">表头的行索引（从0开始）</param>
    /// <param name="sheetIndex">sheet读取的索引（从0开始）</param>
    /// <returns>返回datatable</returns>
    public static DataTable ExcelToDataTable(string filePath, int headRowIndex = 0, int sheetIndex = 0)
    {
        return filePath.ReadExcelToDataTable(headRowIndex, sheetIndex);
    }

    ///<summary>
    /// 将excel导入到 List<IDictionary<string, object>
    /// </summary>
    /// <param name="filePath">excel路径</param>
    /// <param name="headRowIndex">表头的行索引（从0开始）</param>
    /// <returns>返回datatable</returns>
    public static List<DataTable> ExcelToDataTables(string filePath, int headRowIndex = 0)
    {
        return filePath.ReadExcelToDataTables(headRowIndex);
    }

    ///<summary>
    /// 获取excel列名
    /// </summary>
    /// <param name="filePath">excel路径</param>
    /// <returns>返回datatable</returns>
    public static List<string> ReadExcelColumns(string filePath)
    {
        return filePath.ReadExcelColumns();
    }
}